const jwt = require('jsonwebtoken');
const key = 'abc';
const time =  { expiresIn:86400000   }
function setToken(payload){
    const token = jwt.sign(payload, key,time);
    return token
}
function auth(req, res, next) {
    const token = req.headers.authorization;
    if(token){
        jwt.verify(token, key,(err,data)=>{
            if(err){
                console.log('未授权1');
                return res.status(401).send('未授权1');
            }else{
                req.user=data
                next()
            }
        });
    }else{
        console.log('未授权2');
        return res.status(401).send('未授权2');
    }
}
 module.exports = {
    setToken,auth
  }
